import Vue from 'vue'

let scrollbarWidth

export default function getScrollbarWidth() {
  if (Vue.prototype.$isServer) return 0
  if (scrollbarWidth) return scrollbarWidth

  const e = document.createElement('div')
  e.style.position = 'absolute'
  e.style.top = '-9999px'
  e.style.width = '100px'
  e.style.height = '100px'
  e.style.overflow = 'scroll'
  document.body.appendChild(e)
  scrollbarWidth = e.offsetWidth - e.clientWidth
  document.body.removeChild(e)

  return scrollbarWidth
}
